package com.huluobo.a2109kotlinshopping.demo

import com.huluobo.a2109kotlinshopping.R
import com.huluobo.a2109kotlinshopping.base.BaseMVVMActivity
import com.huluobo.a2109kotlinshopping.databinding.ActivityRoomBinding

class RoomActivity : BaseMVVMActivity<ActivityRoomBinding>() {
    override fun initData() {
    }

    override fun initView() {
        UserDatabaseUtil.init(this)
        dataBinding.insert.setOnClickListener {
            UserDatabaseUtil.getAppDatabase().getUserDao().insertUser(
                User(
                    dataBinding.userId.text.toString().toInt(),
                    dataBinding.username.text.toString(),
                    dataBinding.userSex.text.toString().toInt(),
                    dataBinding.userPublicName.text.toString()
                )
            )
        }

        dataBinding.query.setOnClickListener {
            val user =
                UserDatabaseUtil.getAppDatabase().getUserDao().queryUser(dataBinding.userId.text.toString().toInt())
            dataBinding.result.text = user.toString()
        }
    }

    override fun getLayoutId(): Int = R.layout.activity_room
}